//
//  HomePictureScrollView.m
//  Pictorial
//
//  Created by SKY on 15/12/30.
//  Copyright © 2015年 sky. All rights reserved.
//

#import "HomePictureScrollView.h"

#import "WallpaperDownloadView.h"

@implementation HomePictureScrollView

-(void)willMoveToSuperview:(UIView *)newSuperview{
    self.frame = newSuperview.bounds;
    self.backgroundColor = [UIColor blackColor];
    
    self.showsHorizontalScrollIndicator = NO;
    self.showsVerticalScrollIndicator = NO;
    self.pagingEnabled = YES;
}
-(void)setIndex:(NSInteger)index{
    _index = index;
    self.contentOffset = CGPointMake(index * WIDTH, 0);
}
-(void)setPictures:(NSArray *)pictures{
    _pictures = pictures;
    
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = WIDTH;
    CGFloat h = HEIGHT;
    
    for (int index = 0; index < pictures.count; index ++) {
     
        NSDictionary *dict = pictures[index];
        
        WallpaperDownloadView *downloadView = [WallpaperDownloadView nibInitializtion];
        downloadView.removeSuperView = YES;
        [self addSubview:downloadView];
        
        downloadView.frame = CGRectMake(x + w * index, y, w, h);
        
        downloadView.pictureString = dict[@"image_url"];
        downloadView.title = self.title;
        downloadView.desc = self.desc;
    }
    self.contentSize = CGSizeMake(w * pictures.count, h);
}
@end
